<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button class="btn">注册用户</button>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        document.querySelector('.btn').addEventListener(
            'click', () => { 
                axios({
                    url:'http://hmajax.itheima.net/api/register',
                    method: 'post',
                    //提交数据
                    data:{
                        username:'zjl12345',
                        password:'besrey66'
                    }

                }).then(
                    res =>{
                        console.log(res);
                        
                    }
                ).catch(error =>{
                    //处理错误
                    console.log(error.response.data.message);
                    
                })
            }

        )

    </script>
</body>
</html>